// Playground - noun: a place where people can play

import Cocoa


/*********************************************************************
 * The Swift Language Learning  Chapter 09: Property
 *********************************************************************/


//lazy 
class DataImporter {
	var fileName = "data.txt"
}

class DataManager {
	@lazy var importer = DataImporter()
	var data = String[]()
}

let manager = DataManager()
manager.data += "Some data"
manager.data += "Some more data"

manager.importer.fileName //DataImporter now is initial


//get set property
struct Point {
	var x = 0.0, y = 0.0
}

struct Size {
	var width = 0.0, height = 0.0
}

struct AlternativeRect {
	var origin = Point()
	var size = Size()
	var center: Point {
		get {
			let centerX = origin.x + (size.width / 2)
			let centerY = origin.y + (size.height / 2)
			return Point(x: centerX, y: centerY)
		}
		set {
			origin.x = newValue.x - (size.width / 2)
			origin.y = newValue.y - (size.height / 2)
		}
	}
}

//read only
struct Cuboid {
	var width = 0.0, height = 0.0, depth = 0.0
	var volume: Double {
		return width * height * depth
	}
}

let c = Cuboid()
//c.volume = 5.0 error


//Property Observers
class StepCounter {
	var totalSteps: Int = 0 {
		willSet(newTotalSteps) {
			println("About to set totalSteps to \(newTotalSteps)")
		}
		didSet {
			if totalSteps > oldValue  {
				println("Added \(totalSteps - oldValue) steps")
			}
			
			self.totalSteps = 50
		}
	}
}
let stepCounter = StepCounter()
stepCounter.totalSteps = 200


//type property

struct typepro {
	static var name = "hello" //static only support in 'Struct'
}

let t = typepro()
typepro.name = "type"








